<@pagelet title="小页面测试">
<style>
    .toolbar{height: 40px;padding: 5px;}
    .content{height: 600px;display: flex }
    .content-left{width: 40%;background-color: #2b669a;}
    .content-right{width: 60%;background-color: #2b542c;}
</style>
<div class="toolbar">
    <div class="btn-group" role="group">
        <button type="button" id="btn1" data-src="/base/redirect/modular/pagelet/outter" data-target=".content-left" class="btn btn-primary"><i class="fa fa-bolt"></i>加载1</button>
        <button type="button" id="btn2" data-src="/base/redirect/modular/pagelet/pagelet-right" data-target=".content-right" class="btn btn-primary"><i class="fa fa-bolt"></i>加载2</button>
    </div>
</div>
<div class="content">
    <div class="content-left"></div>
    <div class="content-right"></div>
</div>
<#--<div ng-app="myApp" >-->
    <#--<div ng-controller="myCtrl">-->


        <#--名: <input type="text" ng-model="firstName"><br>-->
        <#--姓: <input type="text" ng-model="lastName"><br>-->
        <#--<br>-->
        <#--姓名: {{firstName + " " + lastName}}-->

    <#--</div>-->
<#--</div>-->
<script>
//    pagelet(function(){
//(function(){
//
//        console.log('abc--->',angular);
//        var app = angular.module('myApp', []);
//        app.controller('myCtrl', function($scope) {
//            $scope.firstName = "John";
//            $scope.lastName = "Doe";
//        });
//})();
//    });


    function exec(domId,domContext,param,scripts){

    }

    function createScope(jqDom){
        if(!(jqDom instanceof jQuery)){
            jqDom = $(jqDom);
        }
        return {
            dom:jqDom,
            domId:'',
            domPure:jqDom[0],
            param:{},
            url:'',
            parent:'',
            children:[]
        };
    }


    function execlet(scope,scripts,callback){
        for(var i=0;i<scripts.length;i++){
            eval(scripts[i]);
        }
    }
    function loadlet(scope,dom,url,callback){
        $.get(rober.url(url)+"?pagelet=1",function(text,status){
            var domWrapper = $('<div></div>')
            domWrapper.html(text);
            var scriptTags = $('script',domWrapper);
            var scripts = [];
            scriptTags.each(function(){
                var content = $(this).html();
                if(!content)return;
                content = content.replace(/(^\s*)|(\s*$)/g, "");//去除两端空格
                if(!content)return;
                scripts.push($(this).html());
            });
            scriptTags.remove();

//            for(var i=0;i<scripts.length;i++){
//                console.log(scripts[i]);
//                console.log('--');
//            }
//            console.log('------------------------');
            console.log('动态加载内容',domWrapper.html());

            var domId = "PL"+Math.uuid().replace(/-/g,"");
            domWrapper.attr("id",domId);
            domWrapper.attr("ms-controller",domId);
            dom.append(domWrapper);
            //执行脚本
            var newScope = createScope(domWrapper);
            newScope.domId = domId;
            newScope.parent = scope;
            scope.children.push(newScope);
            execlet(newScope,scripts,callback);
        });
    };

    $(function(){
        $(".btn").click(function(){
            var src = $(this).data("src");
            var target = $(this).data("target");
            if(!src)return;

            var scope = createScope($("body"));
            scope.parent = window;

            loadlet(scope,$(target),src,function(){
                console.log("load callback");
            });
        });
    });

    pagelet(function(){
       console.log('angular',angular);
    });

</script>
</@pagelet>